package com.jeff.android.lab.database.room;

import androidx.room.Room;

import com.jeff.android.lab.jframework.RuntimeManager;

/**
 * @author: dingfeng
 * @date: 2019-11-05
 * @since: 1.0.0
 **/
public class DbHelper {

    private static DbHelper mDbHelper = null;

    private final AppDatabase mDatabase;

    private DbHelper() {
        mDatabase = Room.databaseBuilder(RuntimeManager.instance().getAppContext(), AppDatabase.class, "jeff.db")
                .allowMainThreadQueries()
                .build();
    }

    public static DbHelper instance() {
        synchronized (DbHelper.class) {
            if (mDbHelper == null) {
                mDbHelper = new DbHelper();
            }
        }
        return mDbHelper;
    }

    public AppDatabase getDatabase() {
        return mDatabase;
    }

    public UserDao getUserDao() {
        return mDatabase.userDao();
    }

}
